import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2022-10-16
 * Time: 17:32
 */
//给定一个整数，求他变成斐波那契数列所需要的最小步数
public class TestDemo {
    public static void main(String[] args) {
        Scanner scanner =new Scanner(System.in);
        int n=scanner.nextInt();
        int f1=0;//左斐波那契数列
        int f2=1;//右斐波那契数列
        while(f2<n){
            int f3=f1+f2;
            f1=f2;
            f2=f3;
        }
       // f1<n<=f2,循环结束;
        int min=Math.min(n-f1,f2-n);
        System.out.println(min);

    }
}
